package demo2;

import com.sun.org.apache.regexp.internal.RE;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-23
 * Time: 13:48
 */
public enum TestEnum {
    //枚举对象
    RED(1, "红色"),GREEN(2, "绿色"),BLACK(3, "黑色");

    private  int ordinal;
    private String color;
    private TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i].ordinal());
        }
        System.out.println("=============");

        TestEnum testEnum = TestEnum.valueOf("BLACK");
        System.out.println(testEnum);
        System.out.println("=================");
        System.out.println(RED.compareTo(BLACK));
    }

    public static void main1(String[] args) {
        TestEnum color = RED;
        switch(color) {
            case RED:
                System.out.println("RED");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            default:
                System.out.println("Error");
                break;
        }
    }

}
